package cn.bx.bid.repository;

import cn.bx.bid.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserRepository extends JpaRepository<User,Long> , JpaSpecificationExecutor<User> {

    public List<User> findByNameContaining(String name);

    //验证登录
    public User findByUserNameAndPassword(String username,String password);

    public boolean existsByUserName(String username);
    //public boolean existsById(Long id);
    ///根据用户查找


    public User findByUserName(String username);

    //默认找了全部列;如果有很大的列,定义只要部分列,
    //前提是User有对应的构造方法
    //id,name,username,role
    //只查询部分列
/*    @Query(value = "select new User(id,role,userName,name) from User where userName=?1")
    public User chazhaoByNAme(String username);*/
    //CURD
    @Modifying
    @Query("update User set password=?2 where id=?1")
    int resetPass(long id, String newPass);

}
